Skip to main content

Orders repository

This module manages the user's list of trading orders, providing an OrdersRepository interface to create, update, remove, and filter orders. It also includes the Order data model, which defines the details of each order, including optional take-profit and stop-loss levels for risk management.

OrdersRepository Interface:

interface OrdersRepository {
/**
* Adds a new order to the repository.
*
* @param order The [Order] object to be added.
*/
fun createOrder(order: Order)
/**
* Removes an existing order from the repository.
*
* @param order The [Order] object to be removed.
*/
fun removeOrder(order: Order)
/**
* Updates an existing order in the repository.
*
* @param newOrder The updated [Order] to be saved in the repository.
*/
fun updateOrder(newOrder: Order)
/**
* Retrieves a list of orders filtered by the specified instrument name.
*
* @param instrumentName The name of the instrument to filter orders by.
* @return A list of [Order] objects associated with the specified instrument name.
*/
fun getOrdersByInstrumentName(instrumentName: String): List<Order>
}
/*****/
/**
* Represents an order in the trading application. Each order includes essential details
* like its ID, instrument name, type, quantity, price, position, and optional protection parameters.
*
* @property id Unique identifier for the order.
* @property instrumentName Name of the instrument being traded.
* @property orderType Type of the order (e.g., BUY_LIMIT, SELL_STOP).
* @property quantity Amount of the instrument to be bought or sold.
* @property price Target price for the order execution.
* @property color Hexadecimal color code representing the visual color of the order.
* @property takeProfitPrice Optional target price for taking profit.
* @property stopLossPrice Optional target price for stopping loss.
*/
data class Order(
val id: String,
val instrumentName: String,
val orderType: OrderType,
val quantity: Double,
val price: Double,
val color: String,
val takeProfitPrice: Double?,
val stopLossPrice: Double?,
)
/**
* Enum representing the various types of orders, defining the buy/sell and limit/stop types.
*/
enum class OrderType {
BUY_LIMIT,
BUY_STOP,
SELL_LIMIT,
SELL_STOP,
}